#作业要先完成，才完美
from pprint import pprint
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes.sort(key=lambda x: x.get('grade'))
pprint(f'根据grade来排序的classes={classes}')
print('\n')

f = filter(lambda x: x.get('grade') == 'A', classes)
pprint(f'通过filter语句来筛选出Grade为A的同学:{list(f)}')
print('\n')

def addAge(x):
    x['age'] = x.get('age') + 1
    return x
m = map(addAge, classes)
pprint(f'通过map函数将上述同学的age + 1之后={list(m)}')
print('\n')

# 使用递归函数重构斐波那契函数f(n) = f(n-1) + f(n-2)
def fibs(n):
    if n == 0 or n == 1:
        return n
    else:
        res = fibs(n - 1) + fibs(n - 2)
        if res >= 100:
            return None
        else:
            return res
l = []
for i in range(100):
    res = fibs(i)
    if res == None:
        break
    else:
        l.append(res)
print(f'使用递归函数重构100内的斐波那契函数：{l}')

